package group2assignone.view.administrator;

import group2assignone.func.UCCtoALAdapter;
import group2assignone.model.Manager;
import group2assignone.ucm.administrator.UCCancelEditManager;
import group2assignone.ucm.administrator.UCSaveEditManager;
import group2assignone.view.OurView;
import java.awt.*;
import javax.swing.*;

/**
 * This class public class EditManagerView extends OurView
 * is the view which is executed to enable the editing of a manger
 * it dispals textfields with the exisitng manger data visible and editable
 * @author group2
 */
public class EditManagerView extends OurView {

    private JTextField firstName = new JTextField();
    private JTextField midName = new JTextField();
    private JTextField lastName = new JTextField();
    private JTextField birthDate = new JTextField();
    private JTextField userName = new JTextField();
    private JTextField pWord = new JTextField();
    private JLabel titleLabel = new JLabel("~~~~~~~~~| Please Edit Manager Details |~~~~~~~~~");
    private JLabel firstNameLabel = new JLabel("First Name");
    private JLabel midNameLabel = new JLabel("Middle Name");
    private JLabel lastNameLabel = new JLabel("Last Name");
    private JLabel dOBLabel = new JLabel("Date of Birth");
    private JLabel pWordLabel = new JLabel("Pasword");
    private JLabel uNameLabel = new JLabel("User Name");
    private JButton saveButton = new JButton("Save");
    private JButton cancelButton = new JButton("Cancel");
    private Manager model;



    public EditManagerView(Manager model) {
        this.model = model;
    }

    /**
     * this function retrieves the text in the first name field
     * @return the firstName
     */
    public String getFirstName() {
        return firstName.getText();
    }

    /**
     * this function retrieves the text in the middle name field
     * @return the midName
     */
    public String getMidName() {
        return midName.getText();
    }

    /**
     * this function retrieves the text in the last name field
     * @return the lastName
     */
    public String getLastName() {
        return lastName.getText();
    }

    /**
     * this function retrieves the text in the birth date name field
     * @return the birthDate
     */
    public String getBirthDate() {
        return birthDate.getText();
    }

    /**
     * this function retrieves the text in the username field
     * @return the userName
     */
    public String getUserName() {
        return userName.getText();
    }

    /**
     * this function retrieves the text in the password field
     * @return the pWord
     */
    public String getPWord() {
        return pWord.getText();
    }

    @Override
    public void addComponents() {

        setTitle("Edit Manager Interface");
        firstName.setText(model.getFName());
        lastName.setText(model.getLName());
        birthDate.setText(model.getDob());
        userName.setText(model.getUsername());
        pWord.setText(model.getPassword());

        westPanel.setLayout(new BoxLayout(westPanel, BoxLayout.Y_AXIS));
        eastPanel.setLayout(new BoxLayout(eastPanel, BoxLayout.Y_AXIS));
        centerPanel.setLayout(new GridLayout(5, 2, 5, 0));

        centerPanel.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
        centerPanel.add(firstNameLabel);
        centerPanel.add(firstName);
        centerPanel.add(lastNameLabel);
        centerPanel.add(lastName);
        centerPanel.add(dOBLabel);
        centerPanel.add(birthDate);
        centerPanel.add(uNameLabel);
        centerPanel.add(userName);
        centerPanel.add(pWordLabel);
        centerPanel.add(pWord);
        northPanel.add(titleLabel);
        southPanel.add(cancelButton);
        southPanel.add(saveButton);

        saveButton.addActionListener(new UCCtoALAdapter(new UCSaveEditManager(model, this)));
        cancelButton.addActionListener(new UCCtoALAdapter(new UCCancelEditManager(model, this)));
    }

    /**
     * this function uploads the components into the manager model
     *
     * @param model
     */
    public void upLoad(Manager model) {
        model.setUsername(userName.getText());
        model.setPassword(pWord.getText());
        model.setDob(birthDate.getText());
        model.setFName(firstName.getText());
        model.setLName(lastName.getText());
    }
}
